'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 3_create_struct_tool.py
* @Time: 2025/10/15
* @All Rights Reserve By Brtc
'''
import asyncio
from langchain_core.tools import StructuredTool
from pydantic import BaseModel, Field
class MultyTypeInput(BaseModel):
    a: int = Field(description="第一个参数")
    b: int = Field(description="第二个参数")
def multiply(a:int, b:int) ->int:
    """同步将两个参数相乘"""
    print("同步方法")
    return a*b
async def amultiply(a:int, b:int) ->int:
    """异步将两个参数相乘"""
    print("异步方法")
    return a*b
caculator = StructuredTool.from_function(
    func=multiply,
    coroutine=amultiply,
    name="multiply_tools",
    description="用于将两个参数相乘",
    return_direct=True,
    args_schema=MultyTypeInput,
)
print("函数名称", caculator.name)
print("函数描述", caculator.description)
print("函数参数", caculator.args)
print("是否直接返回", caculator.return_direct)
print(caculator.invoke({"a":10, "b":5}))
asyncio.run(caculator.ainvoke({"a":10, "b":5}))



